<?php
// Framework constants
define('CERBERUS_TAG','php');
define('CERBERUS_ALIAS','cerberus');
define('CERBERUS_PATH',dirname(__FILE__));
defined('CERBERUS_DATE_FORMAT') or define('CERBERUS_DATE_FORMAT','%m-%d-%Y');

// Application constants
define('APPLICATION_ROOT',strtr($_SERVER['DOCUMENT_ROOT'],'/',DIRECTORY_SEPARATOR));
defined('APPLICATION_HOME') or define('APPLICATION_HOME','index');
defined('APPLICATION_ALIAS') or define('APPLICATION_ALIAS','application');
defined('APPLICATION_TEMPLATE') or define('APPLICATION_TEMPLATE','application.templates.default');
defined('APPLICATION_URL') or define('APPLICATION_URL','http://'.$_SERVER['SERVER_NAME']);
defined('APPLICATION_PATH') or define('APPLICATION_PATH',APPLICATION_ROOT.DIRECTORY_SEPARATOR.'application');

/**
 * Show full information about a value
 * @param mixed $param
 */
function debug($param) {
	echo '<code><pre>';
	var_dump($param);
	echo '</pre></code>';
	exit();
}
/**
 * Load user input
 * @param string $param
 * @return mixed
 */
function input($param) {
	if (isset ($_POST[$param])) {
		return $_POST[$param];
	} else {
		return null;
	}
}
/**
 * Import a single class or add a full directory for inclusion
 * @param string $param
 * @return string
 */
function import($param) {
	$path = null;
	$pieces = explode('.', $param);
	$className = array_pop($pieces);
	
	if (class_exists($className, false) || interface_exists($className, false)) {
		return $className;
	}

	if (count($pieces)>0) {
		if ($pieces[0] == CERBERUS_ALIAS) {
			array_shift($pieces);
			$path = CERBERUS_PATH;
		} else if ($pieces[0] == APPLICATION_ALIAS) {
			array_shift($pieces);
			$path = APPLICATION_PATH;
		} else {
			$path = APPLICATION_ROOT;
		}
		$path .= DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $pieces);
	} else {
		$path = APPLICATION_ROOT;
	}

	if ($className == '*') {
		set_include_path(get_include_path().PATH_SEPARATOR.$path);
	} else {
		$path .= DIRECTORY_SEPARATOR.$className.'.class.php';
		if (file_exists($path)) {
			include($path);
			if (!class_exists($className, false) && !interface_exists($className, false)) {
				throw new Exception("Class not found: $param ($path)");
			}
			return $className;
		} else {
			throw new Exception("Class $param could not be loaded ($path)");
		}
	}
}

import('cerberus.core.Annotation');
import('cerberus.core.Cache');
import('cerberus.core.Cerberus');
import('cerberus.core.Parser');
import('cerberus.interface.IFilter');
import('cerberus.interface.IModule');
import('cerberus.interface.ISchema');
import('cerberus.interface.IUser');
import('cerberus.controller.PublicController');

import('application.models.*');
spl_autoload_extensions('.class.php');
spl_autoload_register();
?>
